package com.og.backingbean;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * @author Renaud DIANA
 *
 */
@Entity
@NamedQueries({@NamedQuery(name = "Contract.findAll", query = "SELECT c FROM Contract c ORDER BY c.idContract ASC"),
	@NamedQuery(name = "Contract.findLastMaintenance", query = "SELECT c FROM Contract c ORDER BY c.idContract ASC")})
public class Contract implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String idContract;
	@NotNull
	@NotEmpty
	@Size(max = 50)
	@Column(nullable = false, length = 50)
	private String name;
	@NotNull
	@Past
	@Column(nullable = false)
	@Temporal(TemporalType.DATE)
	private Date startDate;
	@NotNull
	@Future
	@Column(nullable = false)
	@Temporal(TemporalType.DATE)
	private Date endDate;
	@NotNull
	@Column(columnDefinition = "Decimal(6,2)", nullable = false)
	private float price;
	private String comments;
	@NotNull
	@ManyToMany
	@JoinColumn(nullable = false)
	private List<Company> listCompanies;
	@NotNull
	@ManyToOne
	@JoinColumn(nullable = false)
	private Application application;
	@NotNull
	@ManyToOne
	@JoinColumn(nullable = false)
	private Status status;
	@OneToMany(mappedBy = "contract", cascade = CascadeType.ALL)
	@JoinColumn(name = "contract_idcontract")
	private List<Ticket> listTicket;
	
	/**
	 * Default constructor
	 */
	public Contract() {
		// TODO Auto-generated constructor stub
	}

	public String getIdContract() {
		return idContract;
	}

	public void setIdContract(String idContract) {
		this.idContract = idContract;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public List<Company> getListCompanies() {
		return listCompanies;
	}

	public void setListCompanies(List<Company> listCompanies) {
		this.listCompanies = listCompanies;
	}

	public List<Ticket> getListTicket() {
		return listTicket;
	}

	public void setListTicket(List<Ticket> listTicket) {
		this.listTicket = listTicket;
	}

}
